package com.hakim.wfb.schedule.jobs

import com.alibaba.fastjson.JSON
import com.hakim.wfb.schedule.utils.SqlUtil
import com.hakim.cinema.yueke.service.YueKeCinemaService
import com.hakim.wfb.schedule.dao.scheduleDao
import com.hkfs.fundamental.api.data.ObjectResultEx
import groovy.sql.Sql
import org.slf4j.LoggerFactory

/**
 * 用户订单超时处理
 */
class printStatusJob {

    static void doJob() {
//        def jobCode = "printStatusJob"
//        def logger = LoggerFactory.getLogger(jobCode + ".doJob")
//        Sql cinemaSql = SqlUtil.cinemaSql
//        //导入总数
//        int total = 0
//        //错误数
//        int errorNum = 0
//        def updateSql = "UPDATE tb_order_info SET printStatus = 'Y', ticketTime = now() WHERE id = ? "
//        cinemaSql.eachRow("SELECT id,cinemaId,cinemaLinkId,orderId,confirmationId FROM tb_order_info WHERE status = '2' AND printStatus='N'", {
//            if (it?.cinemaLinkId && it?.confirmationId) {
//                List retList = cinemaSql.rows("select printId from tb_ticket_info where orderInfoId= ?", [it.id])
//                def existCount = 0
//                if (retList) {
//                    existCount = retList.size()
//                }
//                if (existCount > 0) {
//                    if (!isAllowPrint(it.cinemaLinkId, retList[0].printId)) {
//                        try {
//                            cinemaSql.executeUpdate(updateSql, [it.id])
//                        } catch (e) {
//                            errorNum++
//                        }
//                        total++
//                    }
//                } else {
//                    ObjectResultEx resultEx = YueKeCinemaService.getTicketInfo(it.cinemaLinkId, it.confirmationId)
//                    if (resultEx.isFailed()) {
//                        return
//                    }
//                    Map data = resultEx.getDataObject()
//                    data.put("orderInfoId", it.id)
//                    data.put("tickets", JSON.toJSONString(data.get("tickets")))
//                    data.put("cinemaLinkId", it.cinemaLinkId)
//                    data.put("cinemaId", it.cinemaId)
//                    data.put("orderId", it.orderId)
//                    cinemaSql.executeInsert(data, "INSERT INTO tb_ticket_info (orderInfoId,cinemaId,cinemaLinkId,orderId," +
//                            "printId,bookingId,confirmationId,showDateTime,cinemaName,hallId,hallName,filmCode,shortName," +
//                            "channelCode,channelName,createDateTime,tickets) " +
//                            "VALUES (:orderInfoId,:cinemaId,:cinemaLinkId,:orderId,:printId,:bookingId,:confirmationId," +
//                            ":showDateTime,:cinemaName,:hallId,:hallName,:filmCode,:shortName,:channelCode,:channelName," +
//                            ":createDateTime,:tickets)")
//                    if (!isAllowPrint(it.cinemaLinkId, data.get("printId"))) {
//                        try {
//                            cinemaSql.executeUpdate(updateSql, [it.id])
//                        } catch (e) {
//                            errorNum++
//                        }
//                        total++
//                    }
//                }
//            }
//        })
//        logger.info(jobCode + "导入完成，总共{}条，已完成{}条，出错{}条", total, total - errorNum, errorNum)
//        scheduleDao.addJobLog(jobCode, total, errorNum)
    }

//    static isAllowPrint(String cinemaLinkId, String printId) {
//        ObjectResultEx ret = YueKeCinemaService.getOrderPrintStatusIsAllow(cinemaLinkId, printId)
//        if (ret.isSuccess()) {
//            return true
//        } else {
//            return false
//        }
//    }

}

